//
//  MovieDetailView.m
//  newDouban
//
//  Created by dllo on 15/10/27.
//  Copyright © 2015年 蓝鸥科技. All rights reserved.
//

#import "MovieDetailView.h"
#import "UIImageView+WebCache.h"
#import "Movie.h"
#import "AllMovieDetailView.h"
@interface MovieDetailView ()

@property (nonatomic, retain) UIScrollView *scrollV;

@end

@implementation MovieDetailView

- (void)dealloc
{
    [_scrollV release];
    [super dealloc];
}


- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self createSubviews];
    }
    
    return self;
}

- (void)createSubviews
{
    
    
//    self.scrollV = [[UIScrollView alloc] initWithFrame:self.frame];
//    [self addSubview:self.scrollV];
//    //self.scrollV.userInteractionEnabled = YES;
//    [_scrollV release];
//    
//    
//    self.scrollV.contentSize = CGSizeMake(414, 245 * 7 + 20 + 40);
//    
//    for (NSInteger i = 0; i < 21; i++) {
//        NSString *name = [NSString stringWithFormat:@"image%ld", i];
//        NSString *namePath = [[NSBundle mainBundle] pathForResource:name ofType:@"jpg"];
//        
//        UIImageView *imageV = [[UIImageView alloc] initWithFrame:CGRectMake(15 + (i % 3) * (110 + 20), 20 + (i / 3) * (170 + 75), 120, 170)];
//        imageV.tag = 1001 + i;
//        imageV.userInteractionEnabled = YES;
//        imageV.image = [UIImage imageNamed:namePath];
//        [self.scrollV addSubview:imageV];
//        [imageV release];
//        
//        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(imageV.frame.origin.x, imageV.frame.origin.y + imageV.frame.size.height + 5, imageV.frame.size.width, 30)];
//        //label.backgroundColor = [UIColor orangeColor];
//        label.textAlignment = NSTextAlignmentCenter;
//        label.text = @"龟兔赛跑";
//        [self.scrollV addSubview:label];
//        [label release];
//        
//        
//        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
//        [imageV addGestureRecognizer:tap];
//        [tap release];
//        
//    }
    
    
}

- (void)setMovieArr:(NSMutableArray *)movieArray
{
    
    self.scrollV = [[UIScrollView alloc] initWithFrame:self.frame];
    [self addSubview:self.scrollV];
    [_scrollV release];
    
    for (NSInteger i = 0; i < movieArray.count; i++) {
        UIImageView *imageV = [[UIImageView alloc] initWithFrame:CGRectMake(15 + (i % 3) * (110 + 20), 20 + (i / 3) * (170 + 75), 120, 170)];
        
        imageV.userInteractionEnabled = YES;
        
        Movie *movie = [movieArray objectAtIndex:i];
        //字符串类型转换为其他类型
        //    NSString *str17 = @"1.5";
        //    float val = [str17 floatValue];
        //    NSLog(@"%.1f", val);

        NSInteger myTag = [movie.myMovieId integerValue];
        imageV.tag = myTag;
        
        NSURL *url = [NSURL URLWithString:movie.pic_url];
        [imageV sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"picholder.png"]];
        
        [self.scrollV addSubview:imageV];
        [imageV release];
        
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(imageV.frame.origin.x, imageV.frame.origin.y + imageV.frame.size.height + 5, imageV.frame.size.width, 30)];
        //label.backgroundColor = [UIColor orangeColor];
        label.textAlignment = NSTextAlignmentCenter;
        label.text = movie.movieName;
        [self.scrollV addSubview:label];
        [label release];
        
//        CGFloat height = AllMovieDetailView heightForContent:<#(NSString *)#> width:<#(CGFloat)#>
        
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
        [imageV addGestureRecognizer:tap];
        [tap release];
        
    }
    
    self.scrollV.contentSize = CGSizeMake(414, 20 + ((movieArray.count + 1) / 3) * (170 + 75) + 65);
    
}


- (void)tapAction:(UITapGestureRecognizer *)tap
{
    NSLog(@"%ld", tap.view.tag);
    NSLog(@"aaaaaa");
    NSString *myTag = [NSString stringWithFormat:@"%ld", tap.view.tag];
    [self.pushDelegate pushToAllMovieDetailViewTag:myTag];
}





/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
